/**************************************************************************
 * @doc UCLAPP
 * @module uclapp.cpp |  
 * Source code used to control UCL Object(s)
 *
 * Product     :   SoftPay 2000 (Global Payment Methodology).
 * <nl>Developer   : 
 * <nl>Notes       :
 *
 * Copyright (c) 1996-2000 by VeriFone Inc. All rights reserved.
 * 
 * No part of this software may be used, stored, compiled, reproduced,
 * modified, transcribed, translated, transmitted, or transferred, in any form 
 * or by any means whether electronic, mechanical, magnetic, optical, 
 * or otherwise, without the express prior written permission of VeriFone, Inc.
   
$Log: /SoftPay/SPK2SIM/Source/Comm/uclapp.cpp $ 
**************************************************************************

   Copyright (C) 1999 by VeriFone, Inc.

   All rights reserved.  No part of this software may be reproduced,
   transmitted, transcribed, stored in a retrieval system, or translated
   into any language or computer language, in any form or by any means,
   electronic, mechanical, magnetic, optical, chemical, manual or otherwise,
   without the prior written permission of VeriFone, Inc.

---------------------------------------------------------------------------*/

#include <project.h>

#define UCLAPP_CPP

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <VerixTimer.h>
#include <svc.h>

/**/#define DEBUG_UCLAPP/**/
#ifdef DEBUG_UCLAPP
#define DEBUG_95
#endif

#include <define.h>
#include <msg.h>
#include <ui.h>
#include <comm.h>
#include <modem.h>
#include <gds.h>
#include <spdebug.h>
#include <uclapp.hpp>
#include <CommObj.hpp>

UCL_LLAppObj::UCL_LLAppObj() {
    int i;

    pdebug(("UCL_LLAppObj()"));

    escapeGuardTime = 1500;
    mdmType = SINGLE_PORT;//KV1 Debug - set in GDS

    for (i = 0; i < MAX_DIAL_LINES; ++i) {
        DialAttempts[i] = 0;
        fNoPhoneNumber[i] = VS_FALSE;
    }
}

short UCL_LLAppObj::GetParam(short paramId,unsigned char* buffer,short size) {
    //KV1 debug
    MODEM_OBJECT* obModem = (MODEM_OBJECT*) obCommunication.Data;

    if ((buffer == NULL) || (size <= 0))
        return E_UCL_INVALID_PARM;

    memset(buffer, 0, size);

    pdebug(("GetParam(%d)", paramId));
    switch (paramId) {
    case ESCAPE_GUARD_TIME:
        sprintf((char *) buffer, "%ld", escapeGuardTime);
        return strlen((char *) buffer);
    case BAUDRATE:
        buffer[0] = shGetCPTBaudRate(obModem->srCPT); //KV1 debug
        buffer[1] = '\0';
        return SINGLE_CHAR_SIZE;
    case FORMAT:
        buffer[0] = shGetCPTDataFormat(obModem->srCPT); //KV1 debug
        buffer[1] = '\0';
        return SINGLE_CHAR_SIZE;
    case PARAMETER:
        vdGetCPTModemParam((char *) buffer, obModem->srCPT); //KV1 debug
        buffer[1] = '\0';
        return SINGLE_CHAR_SIZE;
    case PROTOCOL:
         {
            int protocol = P_char_mode;

            if (shGetCPTDataFormat(obModem->srCPT) == SDLC)
                protocol = P_sdlc_mode;
            buffer[0] = protocol; //KV1 debug
            buffer[1] = '\0';
            return SINGLE_CHAR_SIZE;
        }
    case SDLC_PARM_OPTION:
        buffer[0] = 0; //KV1 debug
        buffer[1] = '\0';
        return SINGLE_CHAR_SIZE;
    case SDLC_PARM_ADDRESS:
        buffer[0] = 0; //KV1 debug
        buffer[1] = '\0';
        return SINGLE_CHAR_SIZE;
    case MDM_TYPE:
        buffer[0] = mdmType;
        buffer[1] = '\0';
        return SINGLE_CHAR_SIZE;
    case DIAL_TYPE:
        if (fGetCPTDialType(obModem->srCPT))
            buffer[0] = PULSE; //KV1 debug
        else
            buffer[0] = TONE; //KV1 debug
        buffer[1] = '\0';
        return SINGLE_CHAR_SIZE;
    case PHONE_NUMBER:
        vdGetCPTPriAuthPhoneNumber((char *) buffer, obModem->srCPT); //KV1 debug
        return strlen((char *) buffer);
    case INIT_STRING:
        strcpy((char *) buffer, "ATS0=2");
        return strlen((char *) buffer);
    case HANGUP_STRING:
        strcpy((char *) buffer, "ATH0");
        return strlen((char *) buffer);
    case STARTUP_STRING:
        strcpy((char *) buffer, "ATE0V0Q0");
        return strlen((char *) buffer); {
            int length;

            inInitModemEnvironmentParam(obModem);
            getkey((char *) MODEM_ENVIRONMENT_VARIABLE, (char *) buffer, (int) size, (char *) 0);
            length = strlen((char *) buffer);
            return (length);
        }
    case MODEL_NO:
        strcpy((char *) buffer, srGDS.modelNo);
        pdebug(("MODEL_NO %s", buffer));
        return strlen((char *) buffer);
    default:
        break;
    }

    return UCL_FAILURE;
};


/********************************************************************************************* 
* @func int | Notify | 
*       UI to prompt for terminal dock.
*
* @parm short | state | 
*       Current terminal dock status.
*
* @rdesc return values.
* @flag int |  Current terminal dock status value
* @end
**********************************************************************************************/
short UCL_LLAppObj::Notify(short state) {
    pdebug(("Notify()"));

    if (state == STATUS_DOCKED)
        state = 0;
    else if (state == STATUS_UNDOCKED) {
        vdDisplayWarningMsg(MUST_DOCK_TERMINAL_MSG21);
        state = 0;
    }
    return state;
}

//  Create an object of CUclFactory class
CUclFactory* uclFactory = new CUclFactory;

//  Create an object of CLLApplObj class 
UCL_LLAppObj* LLAppObj = new UCL_LLAppObj;

void vdInitUCLObjects(void) {
    short retVal;
    char version[10];

    memset(version, 0, sizeof(version));

    //  Get the version no of UCL
    CUcl::GetVersion(version);
    pdebug(("UCL Version '%s'", version));
}

#undef UCLAPP_CPP
